﻿using Sorting.Model;
using Sorting.util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sorting.Common
{
    /*
     * 项目启动的时候加载本地Excel价格表
     */
    class PriceExcelLoader
    {
        public static Dictionary<string, PriceExcel> priceExcelDic = new Dictionary<string, PriceExcel>();

        public static void doIt()
        {
            try {
                // ①读取本地Excel文件列表
                List<FileInfo> fileInfos = ExcelHelper.readLocalPriceExcel("Resources\\");

                // ②遍历文件列表
                foreach (FileInfo fileInfo in fileInfos)
                {

                    // 封装成Dictionary<sheet名, DataTable>
                    PriceExcel priceExcel = new PriceExcel();
                    priceExcel.PriceDic = ExcelHelper.LoadExcel(fileInfo.ToString(), "A4", "F41");
                    priceExcel.DesDic = ExcelHelper.LoadExcel(fileInfo.ToString(), "A42", "F100");

                    //封装成Dictionary<文件名, PriceExcel>
                    priceExcelDic.Add(fileInfo.Name, priceExcel);
                }
            }
            catch (Exception x) {
                throw new Exception(x.Message);
            }
        }

        public static void doIt(FileInfo fileInfo)
        {
            try
            {
                // 封装成Dictionary<sheet名, DataTable>
                PriceExcel priceExcel = new PriceExcel();
                priceExcel.PriceDic = ExcelHelper.LoadExcel(fileInfo.ToString(), "A4", "F41");
                priceExcel.DesDic = ExcelHelper.LoadExcel(fileInfo.ToString(), "A42", "F100");

                //封装成Dictionary<文件名, PriceExcel>
                priceExcelDic.Add(fileInfo.Name, priceExcel);
            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
        }
    }
}
